package org.meow.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.meow.dto.ArticleCateDTO;
import org.meow.entity.ArticleGroup;
import org.meow.result.Result;
import org.meow.service.ArticleCateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * &#064;Date: 24/04/26-13:03
 * &#064;Description:
 */
@RestController
@RequestMapping("/article/cate")
@Tag(name = "文章分类接口")
public class ArticleCateController {

  @Autowired
  private ArticleCateService articleGroupService;

  @PostMapping
  @Operation(summary = "添加文章分类")
  public Result<String> addArticleGroup(@RequestBody ArticleCateDTO articleGroupDTO) {
    articleGroupService.save(articleGroupDTO);
    return Result.success();
  }

  @DeleteMapping("/{id}")
  @Operation(summary = "删除文章分类")
  public Result<String> delArticleGroup(@PathVariable Integer id) {
    return articleGroupService.delete(id)
        ? Result.success() : Result.error("删除失败");
  }

  @PutMapping("/{id}")
  @Operation(summary = "更新文章分类")
  public Result<String> updateArticleGroup(@PathVariable Integer id, @RequestBody ArticleCateDTO articleCateDTO) {
    return articleGroupService.update(id, articleCateDTO)
        ? Result.success() : Result.error("更新失败");
  }

}
